package com.chinasofti1.info_manager.service;

import com.chinasofti1.info_manager.dao.TeacherDao;
import com.chinasofti1.info_manager.domain.Teacher;

public class TeacherService {
    TeacherDao teacherDao = new TeacherDao();

    public boolean isExists(String id)
      {//返回值为true代表不存在
            boolean exists=  false;
            //判断数组中是否有这个id
            int index =teacherDao.getIndex(id);
            if(index == -1){
                exists=true;//不存在
            }
            return  exists;
        }
    public boolean addTeacher(Teacher tch) {
            return teacherDao.addTeacher(tch);
    }
    public Teacher[] findAllTeacher() {
        Teacher[] allTeacher = teacherDao.findAllTeacher();
        boolean  flag = false;//做一个开关 allStudent有值返回 没有值返回null
        for (int i = 0; i <allTeacher.length ; i++) {
            Teacher tch  =allTeacher[i];
            if (tch!=null){
                flag=true;
                break;
            }
        }
        if (flag){
            return allTeacher;
        }else {
            return null;
        }
        }

    public void deleteTeacherById(String id) {
        teacherDao.deleteTeacherById(id);
    }

    public void updateTeacher(String updateId, Teacher newTch) {
        teacherDao.updateTeacher(updateId,newTch);
    }
}

